package cn.hly.service.impl;

import cn.hly.master.dao.PubdleCase000InfoMapper;
import cn.hly.master.dao.SqlMapper;
import cn.hly.master.dao.UrpUserMapper;
import cn.hly.master.pojo.PubdleCase000Info;
import cn.hly.master.pojo.UrpUser;
import cn.hly.service.TestService;
import cn.hly.slave.dao.HeroDao;
import cn.hly.slave.pojo.Hero;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service("testService")
public class TestServiceImpl implements TestService {
    @Autowired
    private HeroDao heroDao;
    @Autowired
    private PubdleCase000InfoMapper case000InfoMapper;
    @Autowired
    private UrpUserMapper urpUserMapper;
    @Autowired
    private SqlMapper sqlMapper;
    @Override
    public JSONObject save(UrpUser user, Hero hero) {
        JSONObject jsonObject=new JSONObject();
        try {
            urpUserMapper.insert(user);
            heroDao.insert(hero);
            jsonObject.put("flag","true");
            jsonObject.put("msg","成功");

        }catch (Exception e){
            e.printStackTrace();
            jsonObject.put("flag","false");
            jsonObject.put("msg",e.getLocalizedMessage());
        }
        return  jsonObject;
    }




    @Override
    public PageInfo<Map<String, Object>> selectPage(int pageNum, int pageSize,Map<String,Object> map) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> appsList = case000InfoMapper.selectPage(map);
        PageInfo<Map<String, Object>> appsPageInfo = new PageInfo<>(appsList);
        return appsPageInfo;
    }

    @Override
    public PageInfo<PubdleCase000Info> selectCasePage(int pageNum, int pageSize, PubdleCase000Info case000Info) {
        PageHelper.startPage(pageNum, pageSize);
        List<PubdleCase000Info> appsList =  case000InfoMapper.selectCasePage(case000Info);
        PageInfo<PubdleCase000Info> pageInfo = new PageInfo<>(appsList);


        return pageInfo;
    }

    @Override
    public JSONObject operate(int pageNum, int pageSize, String sql) {
        PubdleCase000Info case000Info=new PubdleCase000Info();
        case000Info.setId(UUID.randomUUID().toString().replace("-",""));
        case000Info.setcCreatetime(System.currentTimeMillis());
        int n=case000InfoMapper.insertSelective(case000Info);
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String,Object>> appsList =  sqlMapper.selectOperate(sql);
        PageInfo<Map<String, Object>> appsPageInfo = new PageInfo<>(appsList);
        List<Map<String,Object>> appsList2 =  sqlMapper.selectOperate(sql);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("n------",n);
        jsonObject.put("appsPageInfo------",appsPageInfo);
        jsonObject.put("appsList2------",appsList2);
        return jsonObject;
    }


}
